package com.zhxy.util.message;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;

public class MessageCodecEncoder extends ProtocolEncoderAdapter {
	
	private MessageCodec codec;

	public MessageCodec getCodec() {
		return codec;
	}

	public void setCodec(MessageCodec codec) {
		this.codec = codec;
	}

	@Override
	public void encode(IoSession session, Object message,
			ProtocolEncoderOutput out) throws Exception {
		IoBuffer buf = IoBuffer.wrap(codec.encode(message));
		out.write(buf);
	}
}
